<?php
	include_once("king_head.php");
?>

<CENTER>
<H2> Reseller Management - Renewal</H2>
<TABLE border=1 width='90%'>
	<TR>
		<TH>S.No.</TH>
		<TH>Name & email</TH>
		<TH>Manage</TH>
		<TH>DOB</TH>
		<TH>Contact #</TH>
		<TH>Address</TH>
		<TH>Country</TH>
		<TH>Reg. Date</TH>
		<TH>Expiry Date</TH>
		<TH>Days Remaining</TH>
		<TH>Account type</TH>
		<TH>Click to Renew</TH>
		<TH>Click to Remove</TH>
		<TH>Access Website</TH>
	</TR>
<?php
	include_once("ClsSebent/config.php");

	if("$action"=="Renew"){
		$date=date("Y-m-d");
		if("$subs_type"=="M") $end_dt = strftime("%Y-%m-%d", strtotime($join_dt) + mktime(0, 0, 0, 2, 1, 1970));
		if("$subs_type"=="Q") $end_dt = strftime("%Y-%m-%d", strtotime($join_dt) + mktime(0, 0, 0, 4, 4, 1970));
		if("$subs_type"=="S") $end_dt = strftime("%Y-%m-%d", strtotime($join_dt) + mktime(0, 0, 0, 7, 5, 1970));
		if("$subs_type"=="A") $end_dt = strftime("%Y-%m-%d", strtotime($join_dt) + mktime(0, 0, 0, 1, 1, 1971));

		$sql="UPDATE reseller SET active='Y', subs_type='$subs_type', end_dt='$end_dt' WHERE uid='$uid'";
		//echo $sql;
		mysql_query($sql);

		$sql="INSERT INTO subs_detail (uid, start_dt, end_dt, renewal_dt) values('$uid', '$join_dt', '$end_dt', '$date')";
		//echo $sql;
		mysql_query($sql);
	}
	if("$action"=="del"){
		$sql="UPDATE reseller SET active='N' WHERE uid='$uid'";
		//echo $sql;
		mysql_query($sql);
	}

	$sql="SELECT * FROM reseller WHERE active='Y' AND end_dt < DATE_ADD(CURDATE(), INTERVAL 3 MONTH) ORDER BY end_dt";
	$result = mysql_query($sql);
	$num=1;
	while($row=mysql_fetch_array($result)){
		$uid=mysql_escape_string($row["uid"]);
		$pwd=mysql_escape_string($row["pwd"]);
		$fname=mysql_escape_string($row["fname"]);
		$email=$row["email"];
		$dob=$row["DOB"];
		$contact_no=$row["contact_no"];
		$mobile_no=$row["mobile_no"];
		$address=mysql_escape_string($row["address"]);
		$city=mysql_escape_string($row["city"]);
		$state=mysql_escape_string($row["state"]);
		$country=mysql_escape_string($row["country"]);
		$zip=$row["zip"];
		$join_dt=$row["join_dt"];
		$end_dt=$row["end_dt"];
		$subs_type=$row["subs_type"];
		$c_date=date("Y-m-d");
		$qr="select email, (TO_DAYS('".$end_dt."')- TO_DAYS('".$c_date."')) from reseller where uid='".$uid."'";
		//echo $qr;
		$dqr=mysql_query($qr);
		$drw=mysql_fetch_row($dqr);
		$rem_days=$drw[1];
		if($rem_days==0) $rem_days=0;
		echo "<tr>";
		echo "<td> <Form name=frm".$num."><input type=hidden name=site_id value=".$_SESSION['SITE_ID']."><input type=hidden name=uid value=$uid>" . $num . " </td>";
		echo "<td nowrap> $fname <BR> <a href='mailto:" . $email . "'>$email</a> </td>";
		echo "<td nowrap><a href='maintenance.php?site_id=101&rid=".$row['site_id']."' target='_blank'>Manage</a></td>";
		echo "<td nowrap> &nbsp;$dob </td>";
		echo "<td nowrap> Phone: $contact_no <BR> Mobile: $mobile_no </td>";
		echo "<td width='20%'> $address <BR> $city $state $zip </td>";
		echo "<td nowrap> &nbsp;$country </td>";
		echo "<td nowrap> $join_dt </td>";
		echo "<td nowrap><input name=join_dt type=hidden value='$end_dt'>$end_dt</td>";
		echo "<td nowrap>$rem_days</td>";
		echo "<td><select name=subs_type>";
		echo "<option value=M";
		if("$subs_type"=="M") echo " selected";
		echo ">Monthly";
		echo "<option value=Q";
		if("$subs_type"=="Q") echo " selected";
		echo ">Quarterly";
		echo "<option value=S";
		if("$subs_type"=="S") echo " selected";
		echo ">Semi-Annual";
		echo "<option value=A";
		if("$subs_type"=="A") echo " selected";
		echo ">Annual";
		echo "</select></td>";
		echo "<td><input type=submit name=action value=Renew></td>";
		echo "<td><a href=reseller_renewal.php?action=del&site_id=".$_SESSION['SITE_ID']."&uid=" . $uid . ">Suspend</a></td>";?>
		<td><input type="button" value="Website" onclick="javascript: open_site('<?php echo $uid;?>', '<?php echo $pwd;?>');" /> </td>
		<?php
		echo "</tr></form>";
		$num=$num+1;
	}
?>
<input type=hidden name=num value="<?php echo $num; ?>">
</TABLE>
</CENTER>
<script type="text/javascript">
function open_site(usr, pswd)
{
//alert('cpanel.php?uid='+uid+'&pwd='+pwd);
window.open('cpanel.php?uid='+ usr +'&pwd='+ pswd);
}
</script>
<?php
	include_once("king_foot.php");
?>